import { defineStore } from "pinia";
import { getFlatArr, getShowMenuList, getAllBreadcrumbList } from "@/utils/util";
import { AuthState } from "@/stores/interface";
import authMenuList from '@/routers/modules/getRouter'

// AuthStore
export const AuthStore = defineStore({
	id: "AuthState",
	state: (): AuthState => ({
		// 当前页面的 router name，用来做按钮权限筛选
		routeName: "",
		// 按钮权限列表
		authButtonList: {},
		// 菜单权限列表
		authMenuList: []
	}),
	getters: {
		// 后端返回的菜单列表 ==> 这里没有经过任何处理
		authMenuListGet: state => state.authMenuList,
    flatMenuListGet: state => getFlatArr(state.authMenuList),
    // 后端返回的菜单列表 ==> 左侧菜单栏渲染，需要去除 isHide == true
		showMenuListGet: state => getShowMenuList(state.authMenuList),
    // 递归处理后的所有面包屑导航列表
    breadcrumbListGet: state => getAllBreadcrumbList(state.authMenuList)
	},
	actions: {
		async getAuthMenuList() {
			this.authMenuList = authMenuList;
		}
	}
});
